import time

from selenium.webdriver.common.by import By

from common.Utils import ForumDriver

class PostsDetail:
    url=""
    driver=""

    def __init__(self):
        self.url="http://127.0.0.1:9580/index.html"
        self.driver=ForumDriver.driver
        self.driver.get(self.url)

    #网友帖子详情页
    def PostsDetailInternetuser(self):
        #进入论坛首页-点击帖子标题-进入帖子详情页
        #点击网友帖子标题
        time.sleep(8)
        self.driver.find_element(By.CSS_SELECTOR,"#artical-items-body > div:nth-child(1) > div > div.col > div.text-truncate > a > strong").click()
        #进入帖子详情页
        #是否有帖子标题
        self.driver.find_element(By.CSS_SELECTOR, "#details_article_title")
        #是否有帖子内容
        self.driver.find_element(By.CSS_SELECTOR, "#details_article_content")
        #是否有发帖子的网友昵称
        self.driver.find_element(By.CSS_SELECTOR, "#article_details_author_name")
        #是否有发帖子的网友头像
        self.driver.find_element(By.CSS_SELECTOR, "#article_details_author_avatar")
        #是否有点赞按钮
        self.driver.find_element(By.CSS_SELECTOR, "#details_btn_like_count > svg")

        #是否有发私信按钮
        self.driver.find_element(By.CSS_SELECTOR, "#btn_details_send_message > svg").click()
        #测试发私信
        self.driver.find_element(By.CSS_SELECTOR, "#index_message_receive_content").send_keys("测试发私信！")
        self.driver.find_element(By.CSS_SELECTOR, "#btn_index_send_message > svg").click()
        #提示发送成功
        print(self.driver.find_element(By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div > h2").text)

        #是否可以对帖子进行正常评论，成功评论，打印提示信息
        #self.driver.find_element(By.CSS_SELECTOR, "#article_details_reply > div.editormd-preview").send_keys("这个评论！")
        # self.driver.find_element(By.CSS_SELECTOR, "#details_btn_article_reply > svg").click()
        # print(self.driver.find_element(By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div:nth-child(1)").text)

        #评论不输入内容是否有提示
        #self.driver.find_element(By.CSS_SELECTOR, "#article_details_reply > div.editormd-preview").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#details_btn_article_reply > svg").click()
        print(self.driver.find_element(By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div:nth-child(1)").text)

        ForumDriver.getScreenShot()

    #自己的帖子详情页
    def PostDetailMyself(self):
        # 点击自己帖子的标题
        self.driver.find_element(By.CSS_SELECTOR,"#artical-items-body > div:nth-child(3) > div > div.col > div.text-truncate > a > strong").click()
        #测试点赞按钮
        self.driver.find_element(By.CSS_SELECTOR,"#details_btn_like_count > svg").click()
        #测试编辑按钮，是否跳转到编辑页
        self.driver.find_element(By.CSS_SELECTOR,"#details_artile_edit > svg").click()
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div > h2")
        ForumDriver.getScreenShot()

    #测试删除按钮，是否有提示是否删除帖子
    def PostDelet(self):
        # 点击自己帖子的标题
        self.driver.find_element(By.CSS_SELECTOR,"#artical-items-body > div:nth-child(3) > div > div.col > div.text-truncate > a > strong").click()
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-body > div > div > div:nth-child(1) > div.col-9.card.card-lg > div.card-footer.bg-transparent.mt-auto.justify-content-end > div > div:nth-child(3) > div > a > svg").click()
        self.driver.find_element(By.CSS_SELECTOR,"#details_delete_modal > div > div > div.modal-body.text-center.py-4 > svg")
        ForumDriver.getScreenShot()













